﻿using System.Data.SqlClient;
using System.Web;

namespace scmsByAspdNet.cotro.admin {
  /// <summary>
  /// changeCourseInfo 的摘要说明
  /// </summary>
  public class changeCourseInfo : IHttpHandler {

    public void ProcessRequest(HttpContext context) {
      //数据库
      SqlConnection conn = new SqlConnection("Data Source=106.54.69.143;database=scms;uid=sa;pwd=Aspdotnet666");
      conn.Open();
      //提取参数
      string cour_id = context.Request["cour_id"].ToString(),
        title = context.Request["title"].ToString(),
        credit = context.Request["credit"].ToString(),
        hour = context.Request["hour"].ToString(),
        attribute = context.Request["attribute"].ToString(),
        proportion = context.Request["proportion"].ToString(),
        faculty = context.Request["faculty"].ToString(),
        comment = context.Request["comment"].ToString(),
        cover = context.Request["cover"].ToString(),
        status = context.Request["status"].ToString();
      //创建SQL命令
      SqlCommand cmd = new SqlCommand($"update sc_course set title='{title}',credit='{credit}',hour='{hour}',attribute='{attribute}',proportion='{proportion}',faculty='{faculty}',comment='{comment}',cover='{cover}',status='{status}' where id={cour_id};", conn);
      //执行SQL命令
      int res = cmd.ExecuteNonQuery();
      conn.Close();
      //返回数据
      context.Response.StatusCode = 200;
      context.Response.Write($"{{\"code\":0,\"lines\":{res}}}");
    }

    public bool IsReusable {
      get {
        return false;
      }
    }
  }
}